home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Wipes ƒ / Hilbert wipe.c < prev    next >
Text File  |  1994-04-15  |  4KB  |  139 lines

  1. /**********************************************************************\
  2.  
  3. File:        Hilbert wipe.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. /* This fills the screen by a Hilbert space-filling curve, which is defined by
  28.    two mutually recursive drawing functions:
  29.    
  30.    X = left, Y, draw, right, X, draw, X, right, draw, Y, left
  31.    Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
  32.    
  33.    Start by drawing X at the highest recursion level from the bottomleft of the
  34.    screen. (At recursion level 1, X and Y are null functions.)
  35. */
  36.  
  37. #define    RecursionLevel    4
  38. #define CorrectTime 1
  39. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  40. #define theWindowWidth (boundsRect.right-boundsRect.left)
  41.  
  42. pascal void HilbertRecurse(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect,
  43.     int level, int whichpattern, int* x, int* y);
  44. pascal short HilbertWipe(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  45.  
  46. typedef char    Hilby[11];
  47.  
  48. static Hilby    HilbertPattern[]=
  49. {
  50.     {
  51.         0x02,0x69,0x00,0x01,0x42,0x00,0x42,0x01,0x00,0x69,0x02
  52.     },
  53.     {
  54.         0x01,0x42,0x00,0x02,0x69,0x00,0x69,0x02,0x00,0x42,0x01
  55.     }
  56. };
  57.  
  58. static int            HilbertDirection;
  59. static int            vBlockSize;
  60. static int            hBlockSize;
  61. static RgnHandle    boundsRgn;
  62.  
  63. pascal void HilbertRecurse(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect,
  64.     int level, int whichpattern, int* x, int* y)
  65. {
  66.     int                i;
  67.     Rect            source;
  68.     
  69.     for (i=0; i<11; i++)
  70.     {
  71.         switch (HilbertPattern[whichpattern][i])
  72.         {
  73.             case 0x01:     /* turn left */
  74.                 HilbertDirection--;
  75.                 if (HilbertDirection<0) HilbertDirection=3;
  76.                 break;
  77.             case 0x02:     /* turn right */
  78.                 HilbertDirection++;
  79.                 if (HilbertDirection==4) HilbertDirection=0;
  80.                 break;
  81.             case 0x00:    /* draw */
  82.                 StartTiming();
  83.                 SetRect(&source, *x, *y-vBlockSize, *x+hBlockSize, *y);
  84.                 OffsetRect(&source, boundsRect.left, boundsRect.top);
  85.                 CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  86.                                 &source, &source, 0, boundsRgn);
  87.                 switch (HilbertDirection)
  88.                 {
  89.                     case 0:
  90.                         *x+=hBlockSize;
  91.                         break;
  92.                     case 1:
  93.                         *y-=vBlockSize;
  94.                         break;
  95.                     case 2:
  96.                         *x-=hBlockSize;
  97.                         break;
  98.                     case 3:
  99.                         *y+=vBlockSize;
  100.                         break;
  101.                 }
  102.                 TimeCorrection(CorrectTime);
  103.                 break;
  104.             case 0x42:    /* call X */
  105.                 if (level>1)
  106.                     HilbertRecurse(sourceGrafPtr,destGrafPtr,boundsRect,level-1,0,x,y);
  107.                 break;
  108.             case 0x69:    /* call Y */
  109.                 if (level>1)
  110.                     HilbertRecurse(sourceGrafPtr,destGrafPtr,boundsRect,level-1,1,x,y);
  111.                 break;
  112.         }
  113.     }
  114. }
  115.  
  116. pascal short HilbertWipe(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  117. {
  118.     int            curx, cury;
  119.     int            answer, i;
  120.     
  121.     answer=1;
  122.     for (i=0; i<RecursionLevel; i++)
  123.         answer*=2;
  124.     vBlockSize=1+theWindowHeight/answer;    /* used to be 20 */
  125.     hBlockSize=1+theWindowWidth/answer;        /* used to be 32 */
  126.     HilbertDirection=0;
  127.     boundsRgn=NewRgn();
  128.     RectRgn(boundsRgn, &boundsRect);
  129.     cury=theWindowHeight;
  130.     curx=0;
  131.     HilbertRecurse(sourceGrafPtr,destGrafPtr,boundsRect,RecursionLevel,0,&curx,&cury);
  132.     CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  133.                 &boundsRect, &boundsRect, 0, 0L);  /* in case we missed any bits */
  134.     
  135.     DisposeRgn(boundsRgn);
  136.     
  137.     return 0;
  138. }
  139.